
/*

	This file loads data on export support, delivered by the Trade Council in Denmark
	It was delivered in two parts:
	 - promodata.dta: includes all cases where the firm purchased export support
	 - tdc.dta: turned-down cases, included all cases where contact between the TC and the firm was established,
	   but where the firm did not end up purchasing support
	In both data sets, the variable "tdcinitiative" is a dummy variable that takes value 1 if the firm was
	contacted by the TC and zero otherwise.

*/

cd ${work}0_letters

* LOAD
use Company_CVR land year tdcinitiative Company_Name using input\promodata, clear
gen treated=1
append using input\tdc , keep(Company_CVR land year tdcinitiative Company_Name)
replace treated=0 if treated==.

* MODIFY
keep if year>=2002 & year<=2015
keep if land!=""
keep if real(Company_CVR)!=.

* CONSTRUCT INITIAL LETTER (AND DROP OBSERVATION IF OTHER CHARACTER THAN LETTER)
gen letter=substr(Company_Name,1,1)
replace letter=upper(letter)
drop if real(letter)!=.
charlist letter
return list
drop if letter==char(38) | letter==char(43) | letter==char(195)
drop Company_Name

*DROP FIRMS (DEFINED BY ITS IDENTIFIER, COMPANY_CVR) APPEARS WITH DIFFERENT INITAL LETTERS IN SAME YEAR
preserve
	keep Company_CVR year letter
	duplicates drop
	bysort Company_CVR year : keep if _N==1
	save temp\temp, replace
restore
merge m:1 Company_CVR using temp/temp, assert(1 3) keep(3) keepusing(Company_CVR) nogen
erase temp\temp.dta

*COLLAPSE (as in remaining analysis, we do not distinguish between multiple support purchases within a year)
collapse (max) tdcinitiative , by(Company_CVR land year letter)

*GROUP INITIAL LETTERS
gen group=""
replace group="A-E" if inlist(letter,"A","B","C","D","E")
replace group="F-J" if inlist(letter,"F","G","H","I","J")
replace group="K-O" if inlist(letter,"K","L","M","N","O")
replace group="P-T" if inlist(letter,"P","Q","R","S","T")
replace group="U-Z" if inlist(letter,"U","V","W","X","Y","Z")
drop letter

*SAVE
compress
save temp\sample, replace